/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2018-05-13 21:57:59
 * @Description: 外部迭代器 
 */
var Iterator = function(obj) {
  var current = 0;

  var next = function() {
    current += 1;
  }

  var isDone = function() {
    console.log(current)
    return current >= obj.length;
  }

  var getCurrentItem = function() {
    return obj[current];
  }

  return {
    next: next,
    isDone: isDone,
    getCurrentItem: getCurrentItem
  }
}

var compare = function(iterator1,iterator2) {
  while(!iterator1.isDone() && !iterator2.isDone()) {
    if(iterator1.getCurrentItem() !== iterator2.getCurrentItem()) {
      throw new Error('不相等')
    }
    iterator1.next();
    iterator2.next();
  }
  console.log('相等')
}

var iterator1 = Iterator([1,2,3])
var iterator2 = Iterator([1,2,3])

compare(iterator1, iterator2)

console.log(iterator1.next())
